package o;

import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map.Entry;

public class bac {
    private static final HashMap<String, String> ˊ = new HashMap();

    static {
        ˊ.put("FFD8FF", "jpg");
        ˊ.put("89504E47", "png");
    }

    public static String ॱ(String str) {
        String ˎ = ˎ(str);
        if (!dof.ˋ(ˎ)) {
            for (Entry entry : ˊ.entrySet()) {
                if (ˎ.startsWith((String) entry.getKey())) {
                    return (String) entry.getValue();
                }
            }
        }
        return null;
    }

    private static String ˎ(String str) {
        FileInputStream fileInputStream;
        Throwable th;
        String str2 = null;
        try {
            fileInputStream = new FileInputStream(str);
            try {
                byte[] bArr = new byte[4];
                if (-1 != fileInputStream.read(bArr, 0, bArr.length)) {
                    str2 = doa.ˎ(bArr);
                }
                if (fileInputStream != null) {
                    try {
                        fileInputStream.close();
                    } catch (Exception e) {
                        azh.ˏ.ˏ("ImageFileType", "Finally close FileInputStream exception");
                    }
                }
            } catch (Exception e2) {
                try {
                    azh.ˏ.ˏ("ImageFileType", "getFileHeader error");
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (Exception e3) {
                            azh.ˏ.ˏ("ImageFileType", "Finally close FileInputStream exception");
                        }
                    }
                    return str2;
                } catch (Throwable th2) {
                    th = th2;
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (Exception e4) {
                            azh.ˏ.ˏ("ImageFileType", "Finally close FileInputStream exception");
                        }
                    }
                    throw th;
                }
            }
        } catch (Exception e5) {
            fileInputStream = null;
            azh.ˏ.ˏ("ImageFileType", "getFileHeader error");
            if (fileInputStream != null) {
                fileInputStream.close();
            }
            return str2;
        } catch (Throwable th3) {
            Throwable th4 = th3;
            fileInputStream = null;
            th = th4;
            if (fileInputStream != null) {
                fileInputStream.close();
            }
            throw th;
        }
        return str2;
    }
}
